﻿Public Class SoldState
    Implements IState
    Private _machine As GumballMachine

    Public Sub New(ByVal machine As GumballMachine)
        _machine = machine
    End Sub

    Public Sub dispense() Implements IState.dispense
        _machine.ReleaseBall()

        Try
            If _machine.Count > 0 Then
                _machine.CurrentState = _machine.NoQuarterState
            Else
                Console.WriteLine("Oops, out of gumballs!")
                _machine.CurrentState = _machine.SoldOutState
            End If
        Catch ex As Exception
            Console.WriteLine(ex.StackTrace)
        End Try
    End Sub

    Public Sub ejectQuarter() Implements IState.ejectQuarter
        Console.WriteLine("Sorry, you already turned the crank")
    End Sub

    Public Sub insertQuarter() Implements IState.insertQuarter
        Console.WriteLine("Please wait, we're already giving you a gumball")
    End Sub

    Public Sub turnCrank() Implements IState.turnCrank
        Console.WriteLine("Turning twice doesn't get you another gumball!")
    End Sub

    Public Overrides Function ToString() As String
        Return "dispensing a gumball"
    End Function
End Class
